#include "settings/settingsdialog.h"
#include "ui_settingsdialog.h"
#include "settings.h"
#include <QVector>

SettingsDialog::SettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{
    ui->setupUi(this);
	QObject::connect(ui->ampSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sAmpSource1SliderValueChanged(int)));
	QObject::connect(ui->ampSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sAmpSource1SpinBoxValueChanged(double)));
	QObject::connect(ui->ampSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sAmpSource2SliderValueChanged(int)));
	QObject::connect(ui->ampSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sAmpSource2SpinBoxValueChanged(double)));
	QObject::connect(ui->freSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sFreSource1SliderValueChanged(int)));
	QObject::connect(ui->freSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sFreSource1SpinBoxValueChanged(double)));
	QObject::connect(ui->freSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sFreSource2SliderValueChanged(int)));
	QObject::connect(ui->freSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sFreSource2SpinBoxValueChanged(double)));
	QObject::connect(ui->phaSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sPhaSource1SliderValueChanged(int)));
	QObject::connect(ui->phaSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sPhaSource1SpinBoxValueChanged(double)));
	QObject::connect(ui->phaSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sPhaSource2SliderValueChanged(int)));
	QObject::connect(ui->phaSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sPhaSource2SpinBoxValueChanged(double)));
}

SettingsDialog::~SettingsDialog()
{
	QObject::disconnect(ui->ampSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sAmpSource1SliderValueChanged(int)));
	QObject::disconnect(ui->ampSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sAmpSource1SpinBoxValueChanged(double)));
	QObject::disconnect(ui->ampSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sAmpSource2SliderValueChanged(int)));
	QObject::disconnect(ui->ampSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sAmpSource2SpinBoxValueChanged(double)));
	QObject::disconnect(ui->freSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sFreSource1SliderValueChanged(int)));
	QObject::disconnect(ui->freSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sFreSource1SpinBoxValueChanged(double)));
	QObject::disconnect(ui->freSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sFreSource2SliderValueChanged(int)));
	QObject::disconnect(ui->freSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sFreSource2SpinBoxValueChanged(double)));
	QObject::disconnect(ui->phaSource1Slider,SIGNAL(valueChanged(int)),this,SLOT(sPhaSource1SliderValueChanged(int)));
	QObject::disconnect(ui->phaSource1SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sPhaSource1SpinBoxValueChanged(double)));
	QObject::disconnect(ui->phaSource2Slider,SIGNAL(valueChanged(int)),this,SLOT(sPhaSource2SliderValueChanged(int)));
	QObject::disconnect(ui->phaSource2SpinBox,SIGNAL(valueChanged(double)),this,SLOT(sPhaSource2SpinBoxValueChanged(double)));
    delete ui;
}

void SettingsDialog::sAmpSource1SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->ampSource1Slider->setValue(value_int);
    Settings::instance()->setAmplitude(0,value);
}

void SettingsDialog::sAmpSource1SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->ampSource1SpinBox->setValue(value_real);
}

void SettingsDialog::sAmpSource2SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->ampSource2Slider->setValue(value_int);
    Settings::instance()->setAmplitude(1,value);
}

void SettingsDialog::sAmpSource2SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->ampSource2SpinBox->setValue(value_real);
}

void SettingsDialog::sFreSource1SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->freSource1Slider->setValue(value_int);
    Settings::instance()->setFreq(0,value);
}

void SettingsDialog::sFreSource1SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->freSource1SpinBox->setValue(value_real);
}

void SettingsDialog::sFreSource2SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->freSource2Slider->setValue(value_int);
    Settings::instance()->setFreq(1,value);
}

void SettingsDialog::sFreSource2SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->freSource2SpinBox->setValue(value_real);
}

void SettingsDialog::sPhaSource1SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->phaSource1Slider->setValue(value_int);
    Settings::instance()->setPhase(0,value);
}

void SettingsDialog::sPhaSource1SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->phaSource1SpinBox->setValue(value_real);
}

void SettingsDialog::sPhaSource2SpinBoxValueChanged(double value)
{
    int value_int = value*500;
    ui->phaSource2Slider->setValue(value_int);
    Settings::instance()->setPhase(1,value);
}

void SettingsDialog::sPhaSource2SliderValueChanged(int value)
{
    double value_real = (double)value/500.0;
    ui->phaSource2SpinBox->setValue(value_real);
}
